package com.karrim.server.model.abstr;

import com.karrim.server.annotation.Annotation;
import com.karrim.server.model.def.DTO;
import com.karrim.server.model.def.Persistable;
import com.karrim.server.util.Util;
import java.lang.reflect.Modifier;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.InheritanceStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 *
 * @author andrea.cantafio
 */
@PersistenceCapable
@Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
public abstract class AbstractEntity implements Persistable<Long> {

    public AbstractEntity() {
    }

    public DTO<Long> getDTO() {
        if (this.getClass().isAnnotationPresent(Annotation.Portable.class)) {
            Class<?> clazz = this.getClass();
            //String model = Util.get().getClassModel(clazz.getPackage().getName(), new int[] {Modifier.PUBLIC}, clazz.getSimpleName(), fields, null, new Class<?>[]{DTO.class});
        }
        throw new IllegalStateException("Entity must be annotated with @Portable annnotation.");
    }

    @Override
    public Class<Long> getIdClass() {
        return Long.class;
    }

    @Override
    public Long getId() {
        return Id;
    }

    @Override
    public Long setId(Long id) {
        return id;
    }
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    protected Long Id;
}
